/**
 * Copyright(c) 2014 Xunton Solutions
 *
 * History:
 *   15-11-13 下午8:47 Created by dwzhang
 */
package com.jade.modules.protocol;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.*;

/**
 * 协议通道，定义了协议接入的具体参数。
 *
 * @author <a href="mailto:dwzhang@xunton.com">dwzhang</a> 
 * @version 1.0 15-11-13 下午8:47
 */
//@Entity
//@Table (name = "MODULE_PROTOCOL_CHANNEL")
public class ProtocolChannel
        implements Serializable
{
    public static final int STATUS_INACTIVE = 0;
    public static final int STATUS_ACTIVE = 1;

    //标识
    @Id
    @GeneratedValue (generator = "SEQ_MODULE_PROTOCOL_CHANNEL")
    @SequenceGenerator (name = "SEQ_MODULE_PROTOCOL_CHANNEL", sequenceName = "SEQ_MODULE_PROTOCOL_CHANNEL")
    private int id;
    //所有者类型
    @Column (name = "owner_type", length = 32, nullable = false)
    private String ownerType;
    //所有者标识
    @Column (name = "owner_id", length = 64, nullable = false)
    private String ownerId;
    //通道名称
    @Column (name = "name", length = 32, nullable = false)
    private String name;
    //类型
    @Column (name = "type", length = 32, nullable = false)
    private String type;
    //协议
    @Column (name = "protocol", length = 32, nullable = false)
    private String protocol;
    //供应商
    @Column (name = "provider", length = 32)
    private String provider;
    //通道说明
    @Column (name = "remark", length = 256)
    private String remark;
    //通道状态
    @Column (name = "status")
    private int status = STATUS_ACTIVE;
    //排序码
    @Column (name = "sort_code")
    private int sortCode;
    //创建时间
    @Column (name = "creation_date", nullable = false, updatable = false)
    private Date creationDate;
    //更新时间
    @Column (name = "update_date")
    private Date updateDate;
    //协议参数
    @ElementCollection (targetClass = String.class, fetch = FetchType.EAGER)
    @CollectionTable (name = "MODULE_PROTOCOL_CHANNEL_PROPERTY", joinColumns = @JoinColumn (name = "channel_id"))
    @MapKeyColumn (name = "name", length = 32)
    @Column (name = "value", length = 256)
    private Map<String, String> parameters;

    public int getId()
    {
        return id;
    }

    public void setId(int id)
    {
        this.id = id;
    }

    public String getOwnerType()
    {
        return ownerType;
    }

    public void setOwnerType(String ownerType)
    {
        this.ownerType = ownerType;
    }

    public String getOwnerId()
    {
        return ownerId;
    }

    public void setOwnerId(String ownerId)
    {
        this.ownerId = ownerId;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getType()
    {
        return type;
    }

    public void setType(String type)
    {
        this.type = type;
    }

    public String getProvider()
    {
        return provider;
    }

    public void setProvider(String provider)
    {
        this.provider = provider;
    }

    public String getProtocol()
    {
        return protocol;
    }

    public void setProtocol(String protocol)
    {
        this.protocol = protocol;
    }

    public Map<String, String> getParameters()
    {
        return parameters;
    }

    public void setParameters(Map<String, String> parameters)
    {
        this.parameters = parameters;
    }

    public String getParameter(String key)
    {
        return parameters == null ? null : parameters.get(key);
    }

    public void setParameter(String key, String value)
    {
        if (parameters == null) {
            parameters = new HashMap<String, String>();
        }
        parameters.put(key, value);
    }

    public String getRemark()
    {
        return remark;
    }

    public void setRemark(String remark)
    {
        this.remark = remark;
    }

    public int getStatus()
    {
        return status;
    }

    public void setStatus(int status)
    {
        this.status = status;
    }

    public int getSortCode()
    {
        return sortCode;
    }

    public void setSortCode(int sortCode)
    {
        this.sortCode = sortCode;
    }

    public Date getCreationDate()
    {
        return creationDate;
    }

    public void setCreationDate(Date creationDate)
    {
        this.creationDate = creationDate;
    }

    public Date getUpdateDate()
    {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate)
    {
        this.updateDate = updateDate;
    }
}
